package com.vip.iot.controller;

import com.vip.common.constant.UrlConsts;
import com.vip.common.response.RestResponse;
import com.vip.common.response.RestResponses;
import com.vip.iot.service.MqttPubMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * MQTT消息管理
 *
 * @author wgb
 * @date 2020/6/18 11:47
 */
@RestController
@RequestMapping(UrlConsts.API + "/mqtt")
public class MqttMessageController {

    @Autowired
    private MqttPubMsgService mqttPubMsgService;

    /**
     * 推送消息
     *
     * @param topic
     * @param message
     * @return
     */
    @PostMapping(value = "/send")
    public RestResponse<Map<String, String>> publishMessage(@RequestParam String topic, @RequestParam String message){
        return RestResponses.newSuccessResponse(mqttPubMsgService.sentMessageToMqtt(topic, message));
    }

}
